package io.renren.modules.backstage.controller;

import io.renren.common.exception.Result;
import io.renren.modules.backstage.entity.BorrowerEntity;
import io.renren.modules.backstage.entity.ProductEntity;
import io.renren.common.exception.StatusCode;
import io.renren.modules.backstage.service.BorrowerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Date;

@RestController
@RequestMapping("/borrower")
@CrossOrigin
public class BorrowerController {

    @Autowired
    BorrowerService borrowerService;

    /**
     * 添加借款信息接口
     * @param borrowerEntity
     * @return
     */
    @PostMapping("/save")
    public Result save(@RequestBody BorrowerEntity borrowerEntity){
        borrowerEntity.setCreateTime(new Date());
        borrowerService.save(borrowerEntity);
        return  new Result(StatusCode.OK,"添加数据成功",true);
    }

    /**
     * 查询贷款信息接口
     * @param borrowerEntity
     * @return
     */
    @PostMapping("/list")
    public Result getBorrowerList(@RequestBody BorrowerEntity borrowerEntity){
        Result result= borrowerService.getAll(borrowerEntity);
        return result;
    }

    /***
     * 根据贷款ID查询贷款信息
     * @param borrowId
     * @return
     */
    @GetMapping("/getByBorrowId")
    public Result getByBorrowId(@RequestParam("borrowId") int borrowId){
      BorrowerEntity borrowerEntity=  borrowerService.getByBorrowId(borrowId);
        return new Result(StatusCode.OK,"查询数据成功",true,borrowerEntity);
    }
}
